/**
 * 管理初始化
 */
var InfMapping = {
    id: "InfMappingTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
InfMapping.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        	{title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
            {title: $.i18n.prop('mapping.DmzName'), field: 'dmz8', visible: true, align: 'center', valign: 'middle'},
            {title: $.i18n.prop('mapping.DmzCode'), field: 'dmz1', visible: true, align: 'center', valign: 'middle'},
            {title: $.i18n.prop('mapping.LsmsName'), field: 'name', visible: true, align: 'center', valign: 'middle'},
            {title: $.i18n.prop('mapping.LsmsId'), field: 'lsmsId', visible: true, align: 'center', valign: 'middle'},
//            {title: '', field: 'dmz4', visible: true, align: 'center', valign: 'middle'},
//            {title: '', field: 'dmz5', visible: true, align: 'center', valign: 'middle'},
//            {title: '', field: 'dmz6', visible: true, align: 'center', valign: 'middle'},
//            {title: '', field: 'dmz7', visible: true, align: 'center', valign: 'middle'},
//            {title: 'LSMS system primary key', field: 'lsmsId', visible: true, align: 'center', valign: 'middle'},
//            
            {title: $.i18n.prop('mapping.dataType'), field: 'dataType', visible: true, align: 'center', valign: 'middle',
            	formatter:function (value) {
	        		return value;
	            }
            }
//            {title: 'name', field: 'name', visible: true, align: 'center', valign: 'middle'},
//            {title: 'REMARK 备注', field: 'remark', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
InfMapping.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info($.i18n.prop("common.check"));
        return false;
    }else{
        InfMapping.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加
 */
InfMapping.openAddInfMapping = function () {
    var index = layer.open({
        type: 2,
        title: $.i18n.prop("common.add.title"),
        area: ['800px', '650px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/infMapping/infMapping_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看详情
 */
InfMapping.openInfMappingDetail = function () {

    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: $.i18n.prop("common.edit.title"),
            area: ['800px', '550px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/infMapping/infMapping_update/' + this.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除
 */
InfMapping.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/infMapping/delete", function (data) {
            Feng.success($.i18n.prop("common.delete.success"));
            InfMapping.table.refresh();
        }, function (data) {
            Feng.error($.i18n.prop("common.delete.failed"));
        });
        ajax.set("infMappingId",this.seItem.id);
        ajax.start();
    }
};

InfMapping.sync = function(){
	var ajax = new $ax(Feng.ctxPath + "/infMapping/sync", function (data) {
		console.log(data);
	});
	ajax.start();
}

/**
 * 查询列表
 */
InfMapping.search = function () {
    var queryData = {};
    queryData['dmz8'] = $("#dmz8").val();
    queryData['dataType'] = $("#dataType").val();
    queryData['name'] = $("#name").val();
    //InfMapping.table.btInstance.bootstrapTable('refreshOptions',{pageNumber:1});
    //InfMapping.table.btInstance.bootstrapTable("selectPage",1);
    InfMapping.table.refresh({query: queryData});
    InfMapping.table.resetDefaultPage();
};

$(function () {
    var defaultColunms = InfMapping.initColumn();
    var table = new BSTable(InfMapping.id, "/infMapping/list", defaultColunms);
  
    table.setPaginationType("server");
    InfMapping.table = table.init();
});
